package com.dhcc.producter.advance.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.ExchangeBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//@Configuration
public class RabbitmqTTLConfig {

	// 交换机
	@Bean
	public Exchange ttlDirectExchange() {
		Exchange exchange = ExchangeBuilder.directExchange("ttl-direct-exchange").durable(true).build();
		return exchange;
	}

	// 队列
	@Bean
	public Queue ttlDirectQueue() {
		Queue queue = QueueBuilder.durable("ttl-direct-queue")
								.ttl(20000) // 队列中整个消息的过期时间 20s
								.build();
		return queue;
	}

	// 关系
	@Bean
	public Binding ttlDirectExchangeQueue() {
		Binding binding01 = BindingBuilder.bind(ttlDirectQueue()).to(ttlDirectExchange()).with("info").noargs();
		return binding01;
	}

}
